//
//  PreferencesManager.m
//  Tables
//
//  Created by mathias Muller on 9/13/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "PreferencesManager.h"


@implementation PreferencesManager
@synthesize prefCtrl;

static PreferencesManager *sharedSingleton;

+ (PreferencesManager *)defaultInstance {
	@synchronized(self) {
		if (!sharedSingleton) {
			[[PreferencesManager alloc] init];
		}
	}
	return sharedSingleton;
}

+(id)alloc {
	@synchronized(self) {
		NSAssert(sharedSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
		sharedSingleton = [super alloc];
		return sharedSingleton;
	}
}

- (id)init {
	if (self = [super init]) {
		//if([[NSUserDefaults standardUserDefaults]  objectForKey:@"OPERATOR"] == nil)  {
			NSArray *keys = [NSArray arrayWithObjects:@"OPERATOR", @"RANDOM", @"LENGTH", nil];
			NSArray *objects = [NSArray arrayWithObjects:@"X", @"FALSE", @"1", nil];
			NSDictionary *appDefaults = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
			
			NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
			[defaults registerDefaults:appDefaults];
		//}
	}
	return self;
}

-(UIView*)loadPreferenceNIB {
	NSArray* topLevelObjs = [[NSBundle mainBundle] loadNibNamed:@"Preferences" owner:self options:nil];
    if (topLevelObjs == nil) {
        NSLog(@"Error! Could not load Preferences Nib file.\n");
        return nil;
    }
	//TODO fix that 
	self.prefCtrl = [[topLevelObjs objectAtIndex:2] retain];
    return self.prefCtrl.view;
}
@end
